/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import Model.Camino;
import Model.Parametro;
import Model.Pedido;
import Model.PuntoMapa;
import Principals.Main;
import java.util.List;
import org.hibernate.Query;

/**
 *
 * @author walter
 */
public class PlanificacionDAO {
    public static List<PuntoMapa> getPuntosMapa(){
        Main.usrSesion.session.beginTransaction() ;
        Query query = Main.usrSesion.session.createQuery( "from PuntoMapa" ) ;
        Main.usrSesion.session.getTransaction().commit() ;
        return query.list() ;
    }
    
    public static PuntoMapa getPuntoMapaById( int idPunto ){
        Main.usrSesion.session.beginTransaction() ;
        Query query = Main.usrSesion.session.createQuery( "from PuntoMapa where id_punto = :idPunto" ) ;
        query.setParameter( "idPunto" , idPunto ) ;
        Main.usrSesion.session.getTransaction().commit() ;
        PuntoMapa punto = (PuntoMapa)query.uniqueResult() ;
        return punto ;
    }
    
    public static List<Camino> getCaminos(){
        Main.usrSesion.session.beginTransaction() ;
        Query query = Main.usrSesion.session.createQuery( "from Camino" ) ;
        Main.usrSesion.session.getTransaction().commit() ;
        return query.list() ;
    }
    
    public static List<Pedido> getPedidosPendientes(){
        Main.usrSesion.session.beginTransaction() ;
        Query query = Main.usrSesion.session.createQuery( "from Pedido where estado = 0 " ) ;
        Main.usrSesion.session.getTransaction().commit() ;
        return query.list() ;
    }
    
    public static List<Parametro> getVariablesSistema(){
        Main.usrSesion.session.beginTransaction() ;
        Query query = Main.usrSesion.session.createQuery( "from Parametro where tipo_parametro = :tipo" ) ;
        query.setParameter( "tipo" , "VARIABLESISTEMA" ) ;
        Main.usrSesion.session.getTransaction().commit() ;
        return query.list() ;
    }
    
    public static Parametro getVariableSistemaById( int idx ){
        Main.usrSesion.session.beginTransaction() ;
        Query query = Main.usrSesion.session.createQuery( "from Parametro where tipo_parametro = :tipo AND id_padre = :idx" ) ;
        query.setParameter( "tipo" , "VARIABLESISTEMA" ) ;
        query.setParameter( "idx" , idx ) ;
        Main.usrSesion.session.getTransaction().commit() ;
        Parametro variable = (Parametro)query.uniqueResult() ;
        return variable ;
    }
}
